<template>
	<view class="page" style="padding-bottom: 50rpx;">
		<view class="topVue">
			<view class="safeVue" :style="{ height: statusBarHeight + 'rpx' }"></view>
			<view class="flex align-center padding-row30" :style="{ height: barHeight + 'rpx', top: statusBarHeight + 'rpx' }" @click="$tools.back()">
				<image src="../../static/back.png" style="width: 48rpx; height: 48rpx;"></image>
				<text style="line-height: 1; color: #454545; font-weight: 600; font-size: 32rpx; padding-left: 20rpx;">完善资料</text>
			</view>
		</view>
		<view :style="{ height: statusBarHeight + barHeight + 'rpx' }"></view>
		<view class="item flex align-center margin20 padding-row30">
			<view class="label">真实姓名</view>
			<input type="text" placeholder="请输入真实姓名" v-model="name"/>
		</view>
		<view class="item flex align-center margin20 padding-row30">
			<view class="label">昵称</view>
			<input type="text" placeholder="请输入昵称" v-model="nick"/>
		</view>
		<view class="item flex align-center margin20 padding-row30">
			<view class="label">身份证号</view>
			<input type="text" placeholder="请输入身份证号" v-model="idCard"/>
		</view>
		<view class="item flex align-center margin20 padding-row30">
			<view class="label">开户行</view>
			<input type="text" placeholder="请输入开户行" v-model="bank"/>
		</view>
		<view class="item flex align-center margin20 padding-row30">
			<view class="label">银行卡</view>
			<input type="text" placeholder="请输入银行卡" v-model="bankNumber"/>
		</view>
		<view class="item flex align-center margin20 padding-row30" @click="isAddress=true">
			<view class="label">区域</view>
			<view class="flex align-center flex-1">
				<input type="text" placeholder="选择区域" v-model="addName" disabled style="flex:1"/>
				<image src="../../static/more.png" style="width: 38rpx; height: 38rpx;"></image>
			</view>
		</view>
		<view class="item flex align-center margin20 padding-row30">
			<view class="label">地址</view>
			<input type="text" placeholder="请输入地址" v-model="address"/>
		</view>
		<view class="btn margin50" @click="submit()">确定</view>
		
		<u-picker mode="region" :default-region="defaultRegion" v-model="isAddress" confirm-color="#D37430" @confirm="addressConfirm"></u-picker>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				statusBarHeight: 0,
				barHeight: 0,
				name: "",
				bank: "",
				bankNumber: "",
				idCard: '',
				nick: "",
				address: "",
				area: "",
				province: "",
				city: "",
				isAddress: false,
				addName: "",
				defaultRegion: ["湖北省", "武汉市", "江岸区"]
			}
		},
		onLoad() {
			let that = this;
			wx.getSystemInfo({
				success(res) {
					let deviceWidth = wx.getSystemInfoSync().windowWidth
					that.statusBarHeight = Number(res.statusBarHeight) * ( 750 / deviceWidth ) 
					let menuButtonInfo = wx.getMenuButtonBoundingClientRect()
					let barHeight = menuButtonInfo.height + (menuButtonInfo.top - res.statusBarHeight) * 2
					that.barHeight = Number(barHeight) * ( 750 / deviceWidth )
				},
			});
		},
		
		methods: {
			// 选择区域
			addressConfirm(e){
				console.log(e)
				this.province = e.province.label
				this.city = e.city.label
				this.area = e.area.label
				this.addName = `${e.province.label}-${e.city.label}-${e.area.label}`
			},
			async submit(){
				const res =await this.$request("/api/WeChat/updateUserInfo", {
					realName: this.name,    
					name: this.nick,          
					idCard: this.idCard,         
					bankName: this.bank,
					bankCard: this.bankNumber,    
					province: this.province,
					city: this.city,              
					area: this.area,            
					street: this.address          
				}, "POST")
				if(res.code===200) {
					this.$u.toast("操作成功")
					setTimeout(()=>{
						this.$tools.back()
					}, 1000)
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.topVue {
		width: 100%;
		background: #fff;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 99;
		.safeVue {
			width: 100%;
		}
	}
	.item {
		width: 690rpx;
		height: 92rpx;
		background: #fff;
		border-radius: 20rpx;
		box-shadow: 0rpx 0rpx 16rpx 0rpx rgba(178, 178, 178, 0.25), inset 0rpx 8rpx 8rpx 0rpx rgba(255, 255, 255, 0.25);
		.label {
			width: 200rpx;
			color: #454545;
			font-weight: 600;
			line-height: 1;
		}
	}
	
	.btn {
		width: 690rpx;
		height: 92rpx;
		border-radius: 46rpx;
		background: #E37471;
		line-height: 92rpx;
		text-align: center;
		color: #fff;
	}
</style>